﻿//-----------------------------------------------------------------------
// <copyright file="DiagnosticsServiceProxy.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Services
{
    using System;
    
    using System.Collections;
    using System.Collections.Generic;
    
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    
    using System.Xml;
    using System.Xml.Linq;
    
    using CodePlex.Diagnostics.Contracts;
    
    /// <summary>
    /// Provides the service proxy for the <see cref="T:CodePlex.Diagnostics.Contracts.IDiagnosticsService"/>.
    /// </summary>
    public class DiagnosticsServiceProxy : ClientBase<IDiagnosticsService>, IDiagnosticsService
    {
        #region public Guid PublishException(ExceptionDataContract ex, Dictionary<string, string> dictionary, XElement element, IIdentityDataContract identity)

        /// <summary>
        /// Publishes the exception information contained within the specified <see cref="T:CodePlex.Diagnostics.Contracts.ExceptionDataContract"/> to the database.
        /// </summary>
        /// <param name="contract">The <see cref="T:CodePlex.Diagnostics.Contracts.ExceptionDataContract"/> containing the exception information to be published to the database.</param>
        /// <param name="dictionary">A <see cref="T:System.Collections.Generic.Dictionary`2"/> containing name value pairs associated with this exception.</param>
        /// <param name="element">A <see cref="T:System.Xml.Linq.XElement"/> representing an xml element to be associated with this exception.</param>
        /// <param name="identity">The <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/> containing the identity information to be published to the database.</param>
        /// <returns>
        /// A <see cref="T:System.Guid"/> representing the publication identifier for the specified <see cref="T:CodePlex.Diagnostics.Contracts.ExceptionDataContract"/> and <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/>.
        /// </returns>
        public Guid PublishException(ExceptionDataContract contract, Dictionary<string, string> dictionary, XElement element, IIdentityDataContract identity)
        {        
            return this.Channel.PublishException(contract, dictionary, element, identity);
        }

        #endregion

        #region public Guid Log(string entry, LoggingPriority priority, LoggingType type, Dictionary<string, string> dictionary, XElement element, IIdentityDataContract identity)

        /// <summary>
        /// Writes the <see cref="T:System.String"/> using the configured logging provider.
        /// </summary>
        /// <param name="contract">The <see cref="T:CodePlex.Diagnostics.Contracts.LogEntryDataContract"/> containing the log entry information to be published to the database.</param>
        /// <param name="dictionary">A <see cref="T:System.Collections.Generic.Dictionary`2"/> containing name value pairs associated with this log entry.</param>
        /// <param name="element">A <see cref="T:System.Xml.Linq.XElement"/> representing an xml element to be associated with this log entry.</param>
        /// <param name="identity">The <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/> containing the identity information to be published to the database.</param>
        /// <returns>A <see cref="T:System.Guid"/> representing the unique publication identifier for the log entry.</returns>
        public Guid Log(LogEntryDataContract contract, Dictionary<string, string> dictionary, XElement element, IIdentityDataContract identity)
        {
            return this.Channel.Log(contract, dictionary, element, identity);
        }

        #endregion

        #region public void UpdateExitDetails(int processId, DateTime startTime, DateTime exitTime, int exitCode)

        /// <summary>
        /// Updates details about how and when the <see cref="T:System.Diagnostics.Process"/> exited within the CodePlex.Diagnostics database.
        /// </summary>
        /// <param name="processId">The process Id representing the <see cref="T:System.Diagnostics.Process"/> for which details about how and when it exited should be published.</param>
        /// <param name="startTime">The process start time.</param>
        /// <param name="exitTime">The process exit time.</param>
        /// <param name="exitCode">The process exit code.</param>
        /// <remarks>
        /// <para>Process exit details are only published if exceptions were published or log entries were written while the process was alive.</para>
        /// <para>The process is identified by both the process Id and the process start time ensuring that an incorrect process is not identified if the operating system used the same process Id again.</para>
        /// </remarks>
        public void UpdateExitDetails(int processId, DateTime startTime, DateTime exitTime, int exitCode)
        {
            this.Channel.UpdateExitDetails(processId, startTime, exitTime, exitCode);
        }

        #endregion

        #region public void RegisterTeamFoundationServer(TeamFoundationServerDataContract contract)

        /// <summary>
        /// Registers the Team Foundation Server specified by the supplied <see cref="T:Uri"/> within the CodePlex.Diagnostics database.
        /// </summary>
        /// <param name="contract">The <see cref="T:CodePlex.Diagnostics.Contracts.TeamFoundationServerDataContract"/> representing the Team Foundation Server to be registered within the database.</param>
        public void RegisterTeamFoundationServer(TeamFoundationServerDataContract contract)
        {
            this.Channel.RegisterTeamFoundationServer(contract);
        }

        #endregion    
    }
}
